package com.ll.blog.config;

import com.ll.blog.filter.AdminFilter;
import com.ll.blog.filter.UserFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean<AdminFilter> RegistAdminFilter(){
        FilterRegistrationBean<AdminFilter> filter = new FilterRegistrationBean<>();
        filter.setFilter(adminFilter());
//        filter.setName("filter01");
        filter.addUrlPatterns("/api/admin/*");
        filter.addUrlPatterns("/api/user/info");
//        filter.addUrlPatterns("/content/user");
//        filter.setUrlPatterns(Collections.singleton("/admin/*"));
        filter.setOrder(2);
        return filter;
    }

    @Bean
    public AdminFilter adminFilter() {
        return new AdminFilter();
    }

    @Bean
    public FilterRegistrationBean<UserFilter> RegistUserFilter(){
        FilterRegistrationBean<UserFilter> filter = new FilterRegistrationBean<>();
        filter.setFilter(userFilter());
//        filter.setName("filter01");
        filter.addUrlPatterns("/api/admin/*");
        filter.addUrlPatterns("/api/content/user");
        filter.addUrlPatterns("/api/message/user");
        filter.addUrlPatterns("/api/user/info");
//        filter.setUrlPatterns(Collections.singleton("/admin/*"));
        filter.setOrder(1);
        return filter;
    }

    @Bean
    public UserFilter userFilter() {
        return new UserFilter();
    }
}
